namespace EFS.EventLog.Performance
{
	/// <summary>
	/// Performance measuring by marking events
	/// </summary>
	public static class MakrersSeries<T>
	{
		// sync access
		private static System.Object sink = new System.Object();

		/// <summary>
		/// Time series
		/// </summary>
		private static System.Collections.Generic.Dictionary<System.String, Series<T>> series = new System.Collections.Generic.Dictionary<System.String, Series<T>>();

		/// <summary>
		/// Get new marker
		/// </summary>
		/// <param name="seriesName"></param>
		/// <returns></returns>
		public static Marker<T> GetMarker(System.String seriesName, System.String markerDescription)
		{
 			// check
			EFS.Common.Verify.String(seriesName, "seriesName");

			lock (sink)
			{
				// find
				if (series.ContainsKey(seriesName))
				{
					return new Marker<T>(series[seriesName], markerDescription);
				}

				// new
				Series<T> timeSeries = new Series<T>(seriesName);
				series.Add(seriesName, timeSeries);

				// done
				return new Marker<T>(timeSeries, markerDescription);
			}
		}
	}
}